//! Test vectors are from GM/T 0002-2012

mod sm4_modes;

fn main() {
    // 测试ECB模式
    test_ecb_mode();
    
    // 测试CBC模式
    test_cbc_mode();
}

fn test_ecb_mode() {
    println!("===== 测试 SM4 ECB 模式 =====");
    let key = "0123456789abcdef中文".as_bytes();
    let data = b"Hello, SM4 ECB!123"; // 16字节对齐
    
    // 加密
    let encrypted_hex = sm4_modes::sm4_ecb_encrypt(key, data);
    println!("ECB加密结果(hex): {}", encrypted_hex);
    
    // 解密
    let decrypted = sm4_modes::sm4_ecb_decrypt(key, &encrypted_hex);
    let decrypted_text = String::from_utf8_lossy(&decrypted);
    println!("ECB解密结果: {}", decrypted_text);
    
    // 验证
    if data == decrypted.as_slice() {
        println!("ECB模式测试成功: 解密结果与原文一致!");
    } else {
        println!("ECB模式测试失败: 解密结果与原文不一致!");
    }
    println!();
}

fn test_cbc_mode() {
    println!("===== 测试 SM4 CBC 模式 =====");
    let key = b"0123456789abcdef";
    let iv = b"abcdef9876543210";
    let data = b"Hello, SM4 CBC!123"; // 16字节对齐
    
    // 加密
    let encrypted_hex = sm4_modes::sm4_cbc_encrypt(key, iv, data);
    println!("CBC加密结果(hex): {}", encrypted_hex);
    
    // 解密
    let decrypted = sm4_modes::sm4_cbc_decrypt(key, iv, &encrypted_hex);
    let decrypted_text = String::from_utf8_lossy(&decrypted);
    println!("CBC解密结果: {}", decrypted_text);
    
    // 验证
    if data == decrypted.as_slice() {
        println!("CBC模式测试成功: 解密结果与原文一致!");
    } else {
        println!("CBC模式测试失败: 解密结果与原文不一致!");
    }
}

